package com.shequan.shequan.service.impl;

import org.apache.log4j.Logger;

import com.shequan.activity.bean.pojo.Activity;
import com.shequan.activity.bean.pojo.ActivityTag;
import com.shequan.activity.bean.pojo.UserActivityInterestRlt;
import com.shequan.activity.bean.pojo.UserActivitySignRlt;
import com.shequan.activity.dao.ActivityDAO;
import com.shequan.activity.dao.ActivityTagDAO;
import com.shequan.activity.dao.UserActivityInterestRltDAO;
import com.shequan.activity.dao.UserActivitySignRltDAO;
import com.shequan.common.bean.ResultDataStruct;
import com.shequan.shequan.bean.bo.SqActive;
import com.shequan.shequan.bean.pojo.Shequan;
import com.shequan.shequan.dao.ShequanDAO;
import com.shequan.shequan.service.SqActivityService;

public class SqActivityServiceImpl implements SqActivityService{
	
	private static Logger log = Logger.getLogger(SqActivityServiceImpl.class);
	
	private ShequanDAO shequanDAO;
	private ActivityDAO activityDAO;
	private UserActivityInterestRltDAO userActivityInterestRltDAO;
	private UserActivitySignRltDAO userActivitySignRltDAO;
	private ActivityTagDAO activityTagDAO;
	
	public void setShequanDAO(ShequanDAO shequanDAO) {
		this.shequanDAO = shequanDAO;
	}
	
	public void setActivityDAO(ActivityDAO activityDAO) {
		this.activityDAO = activityDAO;
	}
	
	public void setUserActivityInterestRltDAO(
			UserActivityInterestRltDAO userActivityInterestRltDAO) {
		this.userActivityInterestRltDAO = userActivityInterestRltDAO;
	}
	
	public void setUserActivitySignRltDAO(
			UserActivitySignRltDAO userActivitySignRltDAO) {
		this.userActivitySignRltDAO = userActivitySignRltDAO;
	}
	
	public void setActivityTagDAO(ActivityTagDAO activityTagDAO) {
		this.activityTagDAO = activityTagDAO;
	}

	/**
	 * @param shequanId
	 * @return
	 */
	private SqActive getSqActiveMsg(Integer shequanId){
		SqActive sqActive = new SqActive();
		
		//get set from Dao interface
		Shequan shequan = shequanDAO.selectByPrimaryKey(shequanId);
		
		//if not exist shequan, return null
		if (shequan == null) return null;
		
		Activity activity = activityDAO.selectActivityLatest(shequanId);
		Integer activityId = activity.getActivityId();
		UserActivityInterestRlt userInterest = userActivityInterestRltDAO.selectInterestByActivityId(activityId);
		UserActivitySignRlt userSign = userActivitySignRltDAO.selectUserSingByActivityId(activityId);
		ActivityTag activityTag = activityTagDAO.selectByActivityId(activityId);
		
		//set data
		sqActive.setShequan(shequan);
		sqActive.setActivity(activity);
		sqActive.setActivityTag(activityTag);
		sqActive.setInterest(userInterest);
		sqActive.setActivityTag(activityTag);
		sqActive.setUserSign(userSign);

		return sqActive;
	}
	
	/**
	 * @param shequanId
	 * @return
	 */
	public ResultDataStruct<SqActive> shequanAcitiveMsg(Integer shequanId){
		ResultDataStruct<SqActive> res = new ResultDataStruct<SqActive>();
		SqActive sqActive = getSqActiveMsg(shequanId);
		if (sqActive != null){
			res.setBusiSuccess(true);
			res.setData(sqActive);
		}else{
			res.setBusiSuccess(false);
		}
		return res;
	}
}
